<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-12 10:14
 *
 * Version: 2.0
 */

namespace App\Modules\Employee\Repositories;


use App\Models\DynamicResource;
use App\Modules\Employee\Validators\DynamicResourceValidator;
use Flower\Core\Repository\Eloquent\BaseRepository;

class DynamicResourceRepository extends BaseRepository
{
	public function model()
	{
		return DynamicResource::class;
	}

	public function validator()
	{
		return DynamicResourceValidator::class;
	}

	/**
	 * 插入评论资源数据
	 * @param $dynamicId
	 * @param $barberId
	 * @param $resourceId
	 * @return mixed
	 */
	public function insertData($dynamicId,$barberId,$resourceId)
	{
		$resourceInfo =  is_array($resourceId) ?  array_map(function ($v){
			return ['type'=>config('constant.resourceType.picture'),'resource_id'=>$v];
		},$resourceId) : [['type'=>config('constant.resourceType.video'),'resource_id'=>$resourceId]];
		$resourceList = array_map(function($v) use($dynamicId,$barberId){
			return [
				'dynamic_id'   => $dynamicId,
				'user_id'      => $barberId,
				'type'         => $v['type'],
				'resource_id'  => $v['resource_id']
			];
		},$resourceInfo);
		return $this->model->insert($resourceList);
	}

	/**
	 * 删除动态的关联资源
	 * @param $dynamicId
	 * @return int
	 */
	public function deleteByDynamicId($dynamicId){
		return $this->deleteWhere(['dynamic_id'=>$dynamicId]);
	}
}